﻿/*移动Div代码开始*/
var dragapproved=false
var z,x,y;
var first = true;
function move(){
	if (event.button==1&&dragapproved){
		co.style.pixelLeft=temp1+event.clientX-x;
		co.style.pixelTop=temp2+event.clientY-y;
		if(co.style.pixelTop<0)
		{
		    co.style.pixelTop=0;
		}
	return false;
	}
}
function drags(){
	if (!document.all)
	return
	if (event.button==1&&event.srcElement.className=="drag" || event.srcElement.className=="dragMe"){
		dragapproved=true;
		z=null;
		if(event.srcElement.className=="dragMe")
		{
		    z=event.srcElement;
		}
		else
		{
		    z=event.srcElement.parentElement;
		}
		if(first){
		    if(z.style.pixelLeft!=0)
		    {
		        temp1=z.style.pixelLeft;
		    }
		    else if(z.style.pixelRight!=0)//适应右对齐的窗口
		    {
		        temp1=document.body.clientWidth - z.style.pixelRight - z.clientWidth;
		    }
		    else
		    {
		        temp1 = 0;
		    }
		    if(z.style.pixelTop != 0)
		    {
		        temp2=z.style.pixelTop;
		    }
		    else if(z.style.pixelBottom != 0)//适应底部对齐的窗口
		    {
		        temp2=document.body.clientHeight - z.style.pixelBottom - z.clientHeight;
		    }
		    else
		    {
		        temp2 = 0;
		    }
		    first = false;
		}
		else
		{
		    temp1=co.style.pixelLeft;
		    temp2=co.style.pixelTop;
		}
		x=event.clientX;
		y=event.clientY;
		co.style.top = z.style.top;
		co.style.left = z.style.left;
		co.style.width = z.style.width;
		co.style.height = z.style.height;
		co.style.display = "block";
		document.onmousemove=move;
	}
}
document.onmousedown=drags
document.onmouseup=new Function("try{first=true;dragapproved=false;co.style.display='none';z.style.top=co.style.top;z.style.left=co.style.left;}catch(exception){}")
